<template>
 <div  class="components-container">
        <sweet-modal ref="dialog" class="dialog">
            <h3>{{ title }}</h3>
             <div style=" height:200px; margin:30px 50px">

              <div class="layui-form-item">
                <div class="layui-inline">
                  <label class="layui-form-label">所属部门</label>
                  <div class="layui-input-inline">
                           <el-select v-model="MatterData.JPTJPDID" placeholder="请选择部门名称" style="width:100%">
                            <el-option v-for="item in departData" :key="item.JPDID" :label="item.JPDPVDNAME" :value="item.JPDID">
                            </el-option>
                          </el-select>                
                  </div>

                  <label class="layui-form-label">事项类型</label>
                  <div class="layui-input-inline">
                   <el-select v-model="MatterData.JPTTYPE" placeholder="请选择事项类型" style="width:100%">
                            <el-option v-for="item in sthtype" :key="item.Value" :label="item.Text" :value="item.Value">
                            </el-option>
                          </el-select>   
                  </div>
                </div>
              </div>
              <div class="layui-form-item">
                <div class="layui-inline">
                  <label class="layui-form-label">事项标题</label>
                  <div class="layui-input-inline">
                    <el-input v-model="MatterData.JPTTITLE"  placeholder="请输入事项标题" ></el-input>
                  </div>
                   <label class="layui-form-label">事项名称</label>
                  <div class="layui-input-inline">
                    <el-input  v-model="MatterData.JPTNAME"   placeholder="请输入事项名称"></el-input>
                  </div>
                </div>
              </div>
            
              <div class="layui-form-item">
                <div class="layui-inline">
                  <label class="layui-form-label">序号</label>
                  <div class="layui-input-inline">
                    <el-input type="text"   v-model="MatterData.JPTNUM"  placeholder="请输入序号" oninput ="value=value.replace(/[^\d]/g,'')" ></el-input>
                  </div>
                   <label class="layui-form-label">事项内容</label>
                  <div class="layui-input-inline">
                    <el-input type="textarea" medium :autosize="{ minRows: 2, maxRows: 4}"  placeholder="请输入内容" v-model="MatterData.JPTDESC" show-word-limit ></el-input>
                  </div>
                </div>
              </div>
             </div>

            <div class="layui-form-item btnCenter">
              <el-button @click="closeDialog">取消</el-button>
              <el-button type="primary" @click="submit" :loading="loading">确定</el-button>
            </div>
        </sweet-modal>
<!-- 详情 -->
         <sweet-modal ref="dialogInfo" class="dialog">
              <h3>{{ title }}</h3>
               <div style=" height:200px; margin:30px 50px">

              <div class="layui-form-item">
                <div class="layui-inline">
                  <label class="layui-form-label">所属部门</label>
                  <div class="layui-input-inline">
                          <el-input v-model="MatterData.JPDPVDNAME" readonly></el-input>
                  </div>

                  <label class="layui-form-label">事项类型</label>
                  <div class="layui-input-inline">
                      <el-input v-model="MatterData.JPTTYPE" readonly></el-input>

                  </div>
                </div>
              </div>
              <div class="layui-form-item">
                <div class="layui-inline">
                  <label class="layui-form-label">事项标题</label>
                  <div class="layui-input-inline">
                    <el-input v-model="MatterData.JPTTITLE"  placeholder="请输入事项标题" readonly></el-input>
                  </div>
                   <label class="layui-form-label">事项名称</label>
                  <div class="layui-input-inline">
                    <el-input  v-model="MatterData.JPTNAME"   placeholder="请输入事项名称" readonly></el-input>
                  </div>
                </div>
              </div>
            
              <div class="layui-form-item">
                <div class="layui-inline">
                  <label class="layui-form-label">序号</label>
                  <div class="layui-input-inline">
                    <el-input type="text"   v-model="MatterData.JPTNUM"  placeholder="请输入序号" oninput ="value=value.replace(/[^\d]/g,'')" readonly></el-input>
                  </div>
                   <label class="layui-form-label">事项内容</label>
                  <div class="layui-input-inline">
                    <el-input type="textarea" medium :autosize="{ minRows: 2, maxRows: 4}"  placeholder="请输入内容" v-model="MatterData.JPTDESC" show-word-limit readonly ></el-input>
                  </div>
                </div>
              </div>
             </div>
         </sweet-modal>
 </div>
</template>

<script>
import sweetModal from "@/components/sweetModal";
import apiBase from "@/api/apiBase.js";
const ADD = "新增";
const INFO = "详情";
export default {
  name: "DepartmentMatter",
  data() {
    return {
        departData: [],
        sthtype:[],
        title: null,
        loading: false,
        MatterData: {
            
        }
    };
  },
  methods: {
      
    //功能操作
    open(order, id) {
      this.order = order;
      this.dataRepeat();
      switch (this.order) {
        case ADD:
          this.title = "新增";
          this.initSelectData();
          this.$refs.dialog.open();
          break;

        case INFO:
          this.title = "详情";
          this.dataInfo(id);
          this.$refs.dialogInfo.open();
          break;
     
        default:
      }
    },
    //提交
    submit() {
      switch (this.order) {
        case ADD:
          this.dataAdd();
          break;
        case INFO:
          this.$refs.dialogInfo.close();
          break;
        default:
      }
    },

    //数据重置
    dataRepeat() {
      this.MatterData = {};
      
    },
  
          //获取部门下拉
    getdepartDatas() {
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().JointRegConclude.DetailAllJointDept,
        res => {
          this.departData = res.data.content;
        },
        res => {
          this.$message.error(res.data.msg);
        }
      );
    },
          // 获取联办办事事项类型
    getsthtype() {
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Sendcar.GetJptType ,
        res => {
            this.sthtype= res.data.content;
        },
        res => {
          this.$message.error(res.data.msg);
        }
      );
    },
  //初始化下拉框数据
    initSelectData() {
      this.getdepartDatas();
      this.getsthtype()
    },
    //新增提交
    dataAdd() {
      this.loading = true;

      let Data = JSON.parse(JSON.stringify(this.MatterData));
      apiBase.DoService(
        Data,
        apiBase.getApiAdress().JointRegConclude.CreateJointDeptMatter,
        res => {
          this.loading = false;
          this.$refs.dialog.close();

          this.$message({
            type: "success",
            message: "新增成功!"
          });
          this.refreshData();
        },
        res => {
          this.$message.error(res.data.msg);
          this.loading = false;
        }
      );
    },



    //详情
    dataInfo(id) {
      let data = {
        JPTID: id
      };
      apiBase.DoService(data, apiBase.getApiAdress().JointRegConclude.DetailJointDeptMatter, res => {
        this.MatterData = res.data.content;
      });
    },
    closeDialog() {
      if (this.order === ADD || this.order === MODIFY)
        this.$refs.dialog.close();
      else if (this.order === INFO) this.$refs.dialogInfo.close();
    },

    refreshData() {
      this.$emit("refreshData");
    }
  },
  components: {
    sweetModal
  }
};
</script>

<style>

</style>
